package bookSystem;

import java.time.LocalDate;
import java.util.Random;
import java.util.Scanner;

public class BookStore {
    //初始化
    static Book[] books = new Book[4];
    static {
        books[0] = new Book(1, "红楼梦", 50, 10);
        books[1] = new Book(2, "水浒传", 40, 10);
        books[2] = new Book(3, "三国演义", 30, 10);
        books[3] = new Book(4, "西游记", 20, 10);
    }

    public static void main(String[] args) {
        //显示
        showBook(books);
        //购买
        Person p = new Person("张三");
        Book book = p.buyBook(books);
        //结算
        showTotal(book,p);
    }
    //结算
    private static void showTotal(Book book, Person p) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入购买的数量");
        int num = sc.nextInt();
        double total = book.getPrice() * num;
        Random random = new Random();
        int orderNum = random.nextInt();
        System.out.println("订单编号" + Math.abs(orderNum));
        System.out.println("购物时间" + LocalDate.now());
        System.out.println("会员" + p.getName());
        System.out.println("图书名称"+book.getName()+"\t单价："+book.getPrice()+"\t购买数量"+num+",\t共"+total);
    }



    //显示
    private static void showBook(Book[] book) {
        System.out.println("编号\t图书名称\t图书价格\t库存数量");
        for (int i = 0; i < book.length; i++) {
            System.out.println(book[i].getId()+"\t"+book[i].getName());
        }
    }
}

